/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utilities.entities;

import utilities.*;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author olawale
 */
public class SCalendar implements Serializable{

    private String name;
    private DefaultTableModel table;
    private boolean natural;
    private int number;

    private static SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy");

    public SCalendar(DefaultTableModel dtm,String name){
        this(dtm, name, true, 0);
    }
    
    public SCalendar(DefaultTableModel dtm,String name, int no){
        this(dtm, name, false, no);
    }

    public SCalendar(DefaultTableModel dtm, String name, boolean natural, int no){
        this.table = dtm;
        this.name = name;
        this.natural = natural;
        this.number = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DefaultTableModel getTable() {
        return table;
    }

    public boolean isNatural(){
        return true;
    }

    public int getNumber() {
        return number;
    }

    public String[] getMonitors(int row){
        String mona = table.getValueAt(row, 2).toString();
        String monb = table.getValueAt(row, 3).toString();
        return new String [] {mona, monb};
    }

    public String[] getMonitors(Date date){
        int row = findRow(sdf.format(date));
        return getMonitors(row);
    }

    public String[] getMonitors(String date){
        int row = findRow(sdf.format(Utility.parseDate(date)));
        return getMonitors(row);
    }

    public String getDate(int row){
        String date = (String) table.getValueAt(row, 1);
        return date;
    }

    public String getSerial(int row){
        String ser = table.getValueAt(row, 0).toString();
        return ser;
    }

    public String getSerial(String sdate){
        int row = findRow(sdate);
        return getSerial(row);
    }

    public String getSerial(Date date){
        String sdate = sdf.format(date);
        int row = findRow(sdate);
        return getSerial(row);
    }

    public Vector getRow(int row){
        Vector rowData = (Vector) table.getDataVector().get(row);
        return rowData;
    }

    public Vector getRow(String date){
        int row = findRow(date);
        return getRow(row);
    }

    public Vector getRow(Date date){
        String sdate = sdf.format(date);
        int row = findRow(sdate);
        return getRow(row);
    }

    public Object getValueAt(int row, int col){
        return table.getValueAt(row, col);
    }

    public int getRowCount(){
        return table.getRowCount();
    }

    public Vector getColumns(int row){
        Vector rowData = getRow(row);
        return (Vector) rowData.subList(5, rowData.size());
    }

    public int findRow(String date){
        String fdate = (String) table.getValueAt(1, 1);
        if(fdate.substring(0, 3).equals(date.substring(0, 3))){
            for(int r = 0; r < table.getRowCount(); r++){
                String cdate = (String) table.getValueAt(r, 1);
                if(cdate.equals(date)){
                    return r;
                }
            }
        }
        return -9;
    }

    public int findRow(Date date){
        String sdate = sdf.format(date);
        return findRow(sdate);
    }

    @Override
    public String toString() {
        return name;
    }

    





}
